package com.example.henry.yindu.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.design.widget.BottomNavigationView;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.GravityCompat;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.SearchView;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;


import com.ashokvarma.bottomnavigation.BottomNavigationBar;
import com.ashokvarma.bottomnavigation.BottomNavigationItem;
import com.example.henry.yindu.R;
import com.example.henry.yindu.adapter.ListViewItemAdapter;
import com.example.henry.yindu.adapter.RollPagerViewAdapter;
import com.example.henry.yindu.adapter.ViewPagerAdapter;
import com.example.henry.yindu.fragment.AnswerFragment;
import com.example.henry.yindu.fragment.CircleFragment;
import com.example.henry.yindu.fragment.HomeFragment;
import com.example.henry.yindu.fragment.MineFragment;
import com.example.henry.yindu.myclass.ListViewItem;
import com.example.henry.yindu.myclass.MidBar;
import com.jude.rollviewpager.RollPagerView;
import com.jude.rollviewpager.hintview.ColorPointHintView;

import java.util.ArrayList;
import java.util.List;

import static android.R.id.list;

public class FirstPage extends AppCompatActivity implements BottomNavigationBar.OnTabSelectedListener, ViewPager.OnPageChangeListener, View.OnClickListener{

    private BottomNavigationBar bottomNavigationBar;
    private ArrayList<Fragment> fragments;
    private ViewPager viewPager;

    @Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_first_page);
        initBottomBar();
        initViewPager();

    }

    public boolean onCreateOptionsMenu(Menu menu) {
       // getMenuInflater().inflate(R.menu.toolbar, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {

        return true;
    }

    private void initBottomBar() {
        bottomNavigationBar = (BottomNavigationBar)findViewById(R.id.bottom_bar);
        bottomNavigationBar
                .setBarBackgroundColor("#F8F8FF")
                .setActiveColor("#FFA500")
                .setMode(BottomNavigationBar.MODE_FIXED)
                .setBackgroundStyle(BottomNavigationBar.BACKGROUND_STYLE_STATIC)
                .addItem(new BottomNavigationItem(R.drawable.resource, "首页"))
                .addItem(new BottomNavigationItem(R.drawable.answer, "答疑区"))
                .addItem(new BottomNavigationItem(R.drawable.circle, "圈子"))
                .addItem(new BottomNavigationItem(R.drawable.mine, "我的"))
                .setFirstSelectedPosition(0)
                .setTabSelectedListener(this)
                .initialise();
    }

    private void initViewPager() {
        viewPager = (ViewPager)findViewById(R.id.view_pager);
        fragments = new ArrayList<Fragment>();
        fragments.add(new HomeFragment());
        fragments.add(new AnswerFragment());
        fragments.add(new CircleFragment());
        fragments.add(new MineFragment());

        viewPager.setAdapter(new ViewPagerAdapter(getSupportFragmentManager(), fragments));
        viewPager.addOnPageChangeListener(this);
        viewPager.setCurrentItem(0);

    }

    @Override
    public void onTabSelected (int position) {
        viewPager.setCurrentItem(position);
    }

    @Override
    public void onTabUnselected (int position) {
        //viewPager.setCurrentItem(position);
    }

    @Override
    public void onTabReselected (int position) {

    }

    @Override
    public void onPageScrolled (int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected (int position) {
        bottomNavigationBar.selectTab(position);
    }

    @Override
    public void onPageScrollStateChanged (int state) {

    }

    @Override
    public void onClick(View v){}
}
